package com.xdclass.mobile.mobilexdclassredis.controller;

import com.xdclass.mobile.mobilexdclassredis.RedisService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created whit IntelliJ IDEA
 * User:杨骏杰
 * Date:2021/3/14
 * Time:9:32
 */
@RestController
public class RedisController {

    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private RedisService redisService;

    @RequestMapping("/redis/setAndGet")
    @ResponseBody
    public String getAndSetValue(String name,String value){
        redisTemplate.opsForValue().set(name,value);
        return (String) redisTemplate.opsForValue().get(name);
    }
    @RequestMapping("/redis/setAndGet1")
    @ResponseBody
    public String getAndSetValue1(String name,String value){
        redisService.set(name,value);
        return redisService.genValue(name).toString();
    }
}
